﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace is_it_messy
{
    class DetectDuplicateFiles
    {
        public static List<List<FileData>> detectDuplicate(String path)
        {
            List<FileData> datas = Util.GetFilesInfo(path);
            List<List<FileData>> result = new List<List<FileData>>();
            while(datas.Count != 0)
            {
                List<FileData> dup = new List<FileData>();
                FileData current = datas[0];
                Boolean hasDup = false;
                foreach (FileData data in datas)
                {
                    if (compare(current, data))
                    {
                        dup.Add(data);
                        hasDup = true;
                    }
                }

                if (hasDup)
                {
                    dup.Add(current);
                }

                foreach (FileData data in dup)
                {
                    datas.Remove(data);
                }
                result.Add(dup);
            }
            return result;
        }

        //重复文件只考虑文件名不考虑后缀名吗？
        private static Boolean compare(FileData a, FileData b)
        {
            if (a.FileName == b.FileName)
            {
                return true;
            }

            return false;
        }
    }
}
